﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace TrippleGameService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "ITrippleGameService" in both code and config file together.
    [ServiceContract]
    public interface ITrippleGameService
    {
        [OperationContract]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
          UriTemplate = "CreateNewGame")]
        void CreateNewGame(string name);


        [OperationContract]
        [WebInvoke(Method = "POST",
            BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
          UriTemplate = "CreatePlayer")]
        string CreatePlayer(string name);

        [OperationContract]
        [WebInvoke(Method = "POST",
           RequestFormat = WebMessageFormat.Json,
          UriTemplate = "JoinGame")]
        char JoinGame(GameJoiner gameJoiner);

        [OperationContract]
        [WebInvoke()]
        string Move(GameMoveContractor moveContractor);

        [OperationContract]
        [WebInvoke()]
        UpdateContract Update(string gameId);

        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare,
            RequestFormat = WebMessageFormat.Json,
            ResponseFormat = WebMessageFormat.Json)]
        string GetNextPlayer(NextPlayerContractor contractor);

        [OperationContract]
        [WebGet(
            UriTemplate = "ShowAvailableGames")]
        List<GameDTO> ShowAvailableGames();
    }

    [DataContract]
    public class PlayerInfo
    {
        [DataMember]
        public int GameId { get; set; }

        [DataMember]
        public string PlayerId { get; set; }
    }

    [DataContract]
    public class GameJoiner
    {
        [DataMember]
        public int GameId { get; set; }

        [DataMember]
        public string PlayerId { get; set; }
    }

    [DataContract]
    public class NextPlayerContractor
    {
        [DataMember]
        public char PlayerLetter { get; set; }
        [DataMember]
        public string Matrix { get; set; }
        [DataMember]
        public int GameId { get; set; }
    }

    [DataContract]
    public class GameMoveContractor
    {
        [DataMember]
        public int StartX { get; set; }
        [DataMember]
        public int StartY { get; set; }
        [DataMember]
        public int EndX { get; set; }
        [DataMember]
        public int EndY { get; set; }
        [DataMember]
        public char PlayerSymbol { get; set; }
        [DataMember]
        public int GameID { get; set; }
    }

    [DataContract]
    public class UpdateContract
    {
        [DataMember]
        public char? NextPlayerSymbol { get; set; }
        [DataMember]
        public string Matrix { get; set; }
        [DataMember]
        public string GameState { get; set; }
    }
}
